package com.ly.mpayment.persist.service.debituplog;

import java.io.Serializable;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.ly.mpayment.persist.entity.DebitLog;
import com.ly.mpayment.persist.entity.DebitUpLog;
import com.ly.mpayment.persist.hibernate.Page;
import com.ly.mpayment.persist.service.AbstractService;

@Service
public class DebitUpLogServiceImpl extends AbstractService<DebitUpLog, Serializable> implements IDebitUpLogService {

	@Override
	public boolean saveDebitLog(DebitUpLog log) {
		if(log != null){
			this.saveOrUpdate(log);
		}
		return false;
	}

	@Override
	public Page<DebitUpLog> findPageDebitLog(Map<String, Object> parameters, int start, int pageSize) {
		String hql = "select d from DebitUpLog d left join fetch d.upShopInfo us left join fetch d.upOrder up where  d.status = 1  ";
		if(parameters.containsKey("starttime")){
			hql += " and  d.debitTime >= '"+parameters.get("starttime").toString()+" 00:00:00'";
			hql += " and  up.createtime >= '"+parameters.get("starttime").toString()+" 00:00:00'";
			parameters.remove("starttime");
		}
		if(parameters.containsKey("endtime")){
			hql += " and d.debitTime <= '"+parameters.get("endtime").toString()+" 23:59:59'";
			hql += " and up.createtime <= '"+parameters.get("endtime").toString()+" 23:59:59'";
			parameters.remove("endtime");
		}
		hql += " #[ and us.user.useruuid = :useruuid]# #[ and d.upOrder.upphonenum = :phoneNum]# order by d.debitTime desc";
		return this.findPageByNamed(hql, parameters, start, pageSize);
	}

}
